/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package agents;

import env.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 *
 * @author orcas
 */
public class AutomatonAgent extends Agent {
    
    private static AutomatonAgent guard=null;//global variable!
    private final static ImageIcon iconLeft=new ImageIcon("images/sentryLeft.jpg");
    private final static ImageIcon iconRight=new ImageIcon("images/sentryRight.jpg");

    public static AgentState getSentryState() {
        if(guard!=null)
            return guard.getState();
        return null;
    }

    public AutomatonAgent(String name, int row, int col) {
        super(name, row, col);
        guard=this;
        //super.setIcon(iconLeft);
    }
    
    /**
     * this is public, to enable the intelligent agent to predict it's movements.
     * @param sentryState
     * @return
     */
    public static Action nextMove(AgentState sentryState) {
        Action last=sentryState.getLastAction();
        if(last==null)
            last=Action.left;
        if(sentryState.isLegalMove(last))
            return last; //keep going
        return last==Action.left?Action.right:Action.left;
    }
    
    @Override
    public Action getMove() {
        return nextMove(getState());
    }

    @Override
    public boolean isArmed() {
        return true;
    }

    @Override
    public Icon getIcon() {
        if(getState().getLastAction()==Action.right)
            return iconRight;
        return iconLeft;
    }

    
    
}
